package com.jiuzhou.guanwang.jzcp.fragment;

import android.view.View;
import android.widget.ListView;

import com.google.gson.Gson;
import com.jiuzhou.guanwang.jzcp.R;
import com.jiuzhou.guanwang.jzcp.adapter.WorldCupGroupAdapter;
import com.jiuzhou.guanwang.jzcp.base.BaseFragment;
import com.jiuzhou.guanwang.jzcp.bean.GroupResultBean;
import com.jiuzhou.guanwang.jzcp.netutil.NetRequestUtil;
import com.jiuzhou.guanwang.jzcp.utils.TimeUtil;
import com.vise.log.ViseLog;

import org.xutils.common.Callback;

import java.util.HashMap;
import java.util.Map;

public class GroupFragment extends BaseFragment {
    private WorldCupGroupAdapter worldCupGroupAdapter;
    private ListView mJclqLv;

    protected void initView(View view) {
        this.mJclqLv = (ListView) view.findViewById(R.id.lv_sc);
    }

    protected int bindLayout() {
        return R.layout.fragment_world_group;
    }

    protected void initData() {
        Map<String, String> map = new HashMap<>();
        String time = TimeUtil.getDateTimeFromMillisecond(System.currentTimeMillis());
        Callback.Cancelable post = NetRequestUtil.getInstance().get("https://api.dongqiudi.com/data/v1/team_ranking/0?season_id=1800&format_type=1&version=600&refer=data_tab&type=total_ranking",
                null, 101,
                new NetRequestUtil.NetResponseListener<String>() {
                    @Override
                    public void onSuccess(String response, int requestCode) {
                        ViseLog.d(response);
                        GroupResultBean result = (GroupResultBean) new Gson().fromJson(response, GroupResultBean.class);
                        if (result != null ) {
                            if (worldCupGroupAdapter == null) {
                                worldCupGroupAdapter = new WorldCupGroupAdapter(getActivity());
                                mJclqLv.setAdapter(worldCupGroupAdapter);
                            }
                            worldCupGroupAdapter.setData(result.getContent().getRounds().get(0).getContent().getData());
                        }
                    }

                    @Override
                    public void onFailed(String response, int requestCode) {
                        ViseLog.e("请求失败");
                       showToast("返回失败");
                    }

                    @Override
                    public void onError(Throwable e) {
                        showToast("返回解析异常");
                    }

                    @Override
                    public void onFinished() {
                    }
                });
    }
}
